package com.yunduansing.core.factory;

import java.io.IOException;
import java.io.InputStream;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

/**
 * 单例模式创建mybatis sqlsessionfactory
 * @author yunduansing
 *
 */
public enum SqlFactory {
	INSTANCE;
	/**
	 * 单例模式创建mybatis sqlsessionfactory
	 * @return SqlSessionFactory
	 * @throws IOException
	 */
	public SqlSessionFactory getSqlSessionFactory() throws IOException{
		String resource="mybatis-config.xml";
		InputStream inputStream=Resources.getResourceAsStream(resource);
		SqlSessionFactory sqlSessionFactory=new SqlSessionFactoryBuilder().build(inputStream);
		return sqlSessionFactory;
	}
}
